package com.aierkeji.call.b2c.controller;

import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.aierkeji.call.b2c.contants.Contants;
import com.aierkeji.call.b2c.service.AkjCallApprovalHistroService;
import com.aierkeji.call.b2c.util.ResultMapHelper;

@RestController
@RequestMapping("callApprovalHistro")
public class AkjCallApprovalHistroController {
	
	private final Logger log = LogManager.getLogger(getClass());
	
	
	@Autowired
	AkjCallApprovalHistroService akjCallApprovalHistroService;
	
	/**
	 * 查询申请人列表
	 * @param map
	 * @return
	 */
	@PostMapping("findApply")
	//增加了这个注解就可以角色控制
    @RequiresRoles(value= {Contants.ROLE_ID_SALES,Contants.ROLE_ID_MANAGER},logical=Logical.OR)
	public Map<String, Object> findApply(@RequestBody  Map<String, Object> map) {
		
		return akjCallApprovalHistroService.findApply(map);
	}
	
	
	/**
	 * 审批用户
	 * @param map
	 * @return
	 */
	@PostMapping("approvalApplyForUser")
	public Map<String, Object> approvalApplyForUser(@RequestBody  Map<String, Object> map) {
		 try {
			 	return akjCallApprovalHistroService.approvalApplyForUser(map);
			} catch (Exception e) {
				log.error("AkjCallApprovalHistroController.approvalApplyForUser errror --- map:{}", map, e);
				return ResultMapHelper.failure(e.getMessage());
			}
	}
	

	/**
	 * 查看申请结果清单
	 * @param map
	 * @return
	 */
	@PostMapping("applyResult")
	public Map<String, Object> applyResult(@RequestBody Map<String, Object> map){
		
		return akjCallApprovalHistroService.applyResult(map);
	}
	
	/**
	 * 查阅申请结果
	 * @param map
	 * @return
	 */
/*	@PostMapping("checkApplyResult")
	public Map<String, Object> checkApplyResult(@RequestBody Map<String, Object> map){
		
		return akjCallApprovalHistroService.checkApplyResult(map);
	}*/
	
	/**
	 * 清空审批结果
	 * @param map
	 * @return
	 */
	@PostMapping("displayApprovalResult")
	public Map<String, Object> displayApprovalResult(@RequestBody Map<String, Object> map){
		
		return akjCallApprovalHistroService.displayApprovalResult(map);
	}

}
